package pda2glc;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

/**
 *
 * @author Steiger
 */
public class Main {

    public static void main( String[] args ) throws FileNotFoundException
    {
        if ( args.length != 1 ) 
        {
            System.out.println("Entre com UM parametro!");
            return;
        }
        
        File file = null;
        Scanner scFile = null; // Scanner para o arquivo
        Scanner scLine = null; // Scanner para uma linha de um arquivo
        
        try 
        {
            file = new File( args[0] );
            scFile = new Scanner( file );
            scLine = new Scanner( scFile.nextLine() );
        } 
        catch ( FileNotFoundException e ) 
        {
            System.out.println("Arquivo nao encontrado.");
            return;
        }
        
        Automato pda = new Automato(); // Cria um novo automato
        
        while ( scLine.hasNext() ) pda.addEstado( scLine.next() );
        scLine = new Scanner( scFile.nextLine() );
        while ( scLine.hasNext() ) pda.addAlfabetoLinguagem( scLine.next() );
        scLine = new Scanner( scFile.nextLine() );
        while ( scLine.hasNext() ) pda.addAlfabetoPilha( scLine.next() );
        
        String token = new String();

        while ( !token.equals( "*" ) )
        {
            token = scFile.nextLine();
            if ( !token.equals( "*") )
            {
                // REGEXP! Merecia ponto extra por isso, hein Andre!
                token = token.replaceAll( "(\\(|\\)|\\= )", "" );
                scLine = new Scanner( token );
                pda.gerarGramatica( scLine.next(), scLine.next(), 
                        scLine.next(), scLine.next(), scLine.next() );
            }
        }
    }
}
